#include <iostream>
using namespace std;

//抽象类
class Shape {
public:
	Shape (int x, int y):m_x(x), m_y(y) {}
#if 0
	virtual void draw (void) {//虚函数
		//调用虚函数时, 不再由指针类型决定调用哪个版本, 
		//而是由指针所指向的实际目标对象来决定
		cout << "绘制图形:" << m_x << ',' << m_y <<endl;
	}
#endif
	virtual void draw (void) = 0; //纯虚函数
protected:
	int m_x;
	int m_y;
};

class Rect:public Shape {
public:
	Rect (int x, int y, int h, int w):Shape(x, y), m_h(h), m_w(w) {}
	void draw (void) {
		cout << "绘制矩形:" << m_x << ',' << m_y << ',' << m_w << ',' << m_h << endl;
	}
private:
	int m_h;
	int m_w;
};

class Circle:public Shape {
public:
	Circle (int x, int y, int r):Shape(x, y), m_r(r) {}
	void draw (void) {
		cout << "绘制圆形:" << m_x << ',' << m_y << ',' << m_r << endl;
	}
private:
	int m_r;
};

void render (Shape *buffer[]) {
	for (int i = 0; buffer[i]!= NULL; i++) {
		//调用的是基类的draw函数
		buffer[i] -> draw();
	}
}


int main (void)
{
	Shape *buffer[256] = {NULL};
	buffer[0] = new Rect(1,2,3,4); //向上造型
	buffer[1] = new Circle(1,2,3); //向上造型
	buffer[2] = new Rect(14,15,16,17); //向上造型
	buffer[3] = new Rect(1,2,3,41); //向上造型
	buffer[4] = new Circle(5,6,7); //向上造型
	buffer[5] = new Rect(11,12,13,14); //向上造型

	render (buffer);

	//Shape s(10,20);
	return 0;
}
